
#include "controller.h"
#include "pluginsmanager.h"
#include "ui/mainwindow.h"

class ControllerPrivate
{
public:
    ControllerPrivate(Controller *parent = nullptr);
    ~ControllerPrivate();

    PluginsManager *pluginsmanager;
    MainWindow *mainwindow;

private:
    Controller * const q_ptr;
    Q_DECLARE_PUBLIC(Controller)
};

ControllerPrivate::ControllerPrivate(Controller *parent) : q_ptr(parent)
{
    pluginsmanager = new PluginsManager();
    mainwindow = new MainWindow();

    Controller::connect(pluginsmanager, &PluginsManager::PluginLoaded, mainwindow, &MainWindow::OnPluginLoaded);
    Controller::connect(mainwindow, &MainWindow::CurrentPluginChanged, pluginsmanager, &PluginsManager::SetCurrentPlugin);
}

ControllerPrivate::~ControllerPrivate()
{
    delete pluginsmanager;
    delete mainwindow;
}

Controller::Controller(QObject *parent) : QObject{parent}, d_ptr(new ControllerPrivate(this))
{}

Controller::~Controller()
{}

void Controller::Run()
{

    Q_D(Controller);

    d->mainwindow->show();
    d->pluginsmanager->LoadAllPlugins();
}
